﻿using System;
using Bricks.Logging;
using log4net;

namespace Bricks.log4net.Logging
{

    /// <summary>
    /// 
    /// </summary>
    public class LogFacade : LoggerFacadeBase<ILog>, ILogFacade
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="log"></param>
        public LogFacade(ILog log) :
            base(() => log)
        {
            if (log == null)
            {
                throw new ArgumentNullException("log");
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public override void Debug(object message)
        {
            Execute(
                log =>
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(message);
                    }
                });
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public override void Error(object message)
        {
            Execute(
                log =>
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error(message);
                    }
                });
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public override void Fatal(object message)
        {
            Execute(
                log =>
                {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(message);
                    }
                });
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public override void Info(object message)
        {
            Execute(
                log =>
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info(message);
                    }
                });
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public override void Warn(object message)
        {
            Execute(
                log =>
                {
                    if (log.IsWarnEnabled)
                    {
                        log.Warn(message);
                    }
                });
        }
    }
}
